import java.util.Arrays;
import java.util.Comparator;

public class SelectionSort {
    public static <E extends Comparable<E>> void sort(E[] data) {
        for (int i = 0; i < data.length; ++i) {
            int minIndex=i;
            for (int j=i; j<data.length;++j){
             if (data[j].compareTo(data[minIndex])<0){
                 minIndex=j;
             }
            }
          swap(data,minIndex,i);
        }
        System.out.println(Arrays.toString(data));
    }
    private static <E> void swap(E[] data, int minIndex, int index) {
        E exchange=data[index];
        data[index]=data[minIndex];
        data[minIndex]=exchange;
    }

    public static void main(String[] args) {
        Integer[] data={10,6,7,3,2,1,5,4};
        SelectionSort.sort(data);
    }
}
